<?php

/* WICHTIG: In der header.php des Themes muss wp_head(); notiert sein! */

function my_description () {
    if (
	is_home () ||
	is_front_page () ||
	is_single () ||
	is_page () ||
	is_category ()
    ) {
	$str = '';
	if (is_home() || is_front_page ()) {
	    $str = 'Deine individuelle Blogbeschreibung mit max. 160 Zeichen';
	} elseif (is_single() || is_page()) {
	    global $wp_query;
	    $str = $wp_query->post->post_content;
	} elseif (is_category()) {
	    $str = category_description ();
	}
	$str = my_page_str ('', ': ') . $str;
	$str = strip_tags ($str);
	if (strlen ($str) > 160) {
	    $str = mb_substr ($str, 0, 160);
	    $str = mb_split (' ', $str);
	    array_pop ($str);
	    $str = implode (' ', $str) . ' …';
	}

?>
<meta name="description" content="<?php echo htmlspecialchars ($str); ?>"/>
<?php

    }
}
add_action ('wp_head', 'my_description');

?>
